package VN.EDU.IMIC.DEVELOPER.VUVANLUANSWINGJTABLEJSON;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerException;

public class ThemStudentSQL {
	public static void main(String[] args) throws SQLException{
		//1.khai bao doi tuong Connection
		Connection objconnection;
		
		//2.khai bao va khoi tao doi tuong SQL serverdatasource
		
		SQLServerDataSource objdatasource = new SQLServerDataSource();
		objdatasource.setServerName("192.168.88.104");
		objdatasource.setUser("hocvien");
		objdatasource.setPassword("nothing");
		objdatasource.setDatabaseName("Student");
		objdatasource.setPortNumber(1433);
		//3.mo ket noi
		try {
			objconnection = objdatasource.getConnection();
			// kiem tra thong tin ket noi
				if(!objconnection.isClosed()){
					CallableStatement objSt = null;
			// khoi tao doi tuong statetame
					objSt = objconnection.prepareCall("{call Themstudent(?,?,?,?,?)}");	
	        objSt.setString("ID", "9");
			objSt.setString("Fullname", "tran van cuong9");
	        objSt.setString("email", "t9vc@gmail.com");
	         objSt.setString("phone", "91234234");
			objSt.setString("mark", "99");
				System.out.println("them thanh cong");
					objSt.execute();}
			else{System.out.println("Ket noi that bai");}
		} catch (SQLServerException e) {
			System.out.println("erroor" + e.getMessage());
		}
	/*create procedure Themstudent
@ID nvarchar(50),
@Fullname nvarchar(50),
@email nvarchar(50),
@phone nvarchar(50),
@mark nvarchar(50)
AS
begin
insert into Student(ID,Fullname,email,phone,mark)
values(@ID,@Fullname,@email,@phone,@mark)
end
go
*/
	}
	}


